package com.smartEdu.module.schedule;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import com.smartEdu.module.schedule.GobalConstant;
import com.smartEdu.utils.IOUtils;

public class CalenderInquiry {   //校历查询
	private String querySchcalender = GobalConstant.QUERY_SCH_CALENDER;
	
	public void queryCalender() throws IOException, IOException{
		CloseableHttpClient client = HttpClients.createDefault();
		//建立post对象
		HttpPost queryCalnPost = new HttpPost(querySchcalender);
		//把Cookie传给头信息
		queryCalnPost.setHeader("Cookie",Login.Cookie);;
		//建立一个NameValuePair数组，用于存储欲传送的参数
		List<NameValuePair> calnPair = new ArrayList<NameValuePair>();
		//设置所传参数
		UrlEncodedFormEntity entitySource = new UrlEncodedFormEntity(calnPair);
		queryCalnPost.setEntity(entitySource);
		//发送Post,返回一个HttpResponse对象
		HttpResponse responseCaln = client.execute(queryCalnPost);
		String html = IOUtils.getHtml(responseCaln.getEntity().getContent(), "utf-8");
		Document docCalender = 	Jsoup.parse(html);
		Elements eleCalender = docCalender.select("table").select("tr");
		for(int i = 2 ; i < eleCalender.size();i++){
			System.out.println(eleCalender.get(i).text()+" ");
		}
		client.close();
	}
}
